<div class="list-body">
	<form id="comm-search-form">
	<div class="row">
		<div class="search-input">
			<div style="display: none;">
                    <input type="text" name="pageCurrent" value="1">
                    <input type="text" name="pageSize" value="12">
                </div>
        	  <!-- <button type="button" onclick="submit_btn()" class="search-btn" data-icon="search"></button> -->
    	</div>
    	<a class="add-btn" onclick="dialog_communicationprotocol_add()"><i class="fa fa-plus-square-o"></i><span>添加通信协议字典</span></a>
	</div>
	<ul class="row commu-list-content list-content">

	</ul>
    </form>
	<div id="pagination_commu" style="text-align: center; display: none;"></div>

</div>

<script type="text/javascript">
$(function(){
   var communicationprotocolTotalNum ;
    pagination_callback(1, 12,1);
    $("input").placeholder();

    // submit_btn();
})

function submit_btn(){
		BJUI.ajax('ajaxform', {
		    url: '/communicationprotocol/list',
		    form: $.CurrentNavtab.find('#comm-search-form'),
		    validate: false,
		    okalert:false,
		    loadingmask: true,
		    okCallback: function(json, options) {
		    	$('#pagination_commu').pagination('destroy')     //删？
		    	$('#pagination_commu').pagination({
			   	 	total:json.totalRow, pageSize:12, callback:pagination_callback
				})
		    	communicationprotocolTotalNum=json.totalRow;
          	set_list(json);
            if(json.totalRow<=12){
                $("#pagination_commu").css("display","none");
              }else{
                $("#pagination_commu").css("display","block");
            }
		    }
		})
	}

function pagination_callback(pageCurrent, pageSize,num) {
	    BJUI.ajax('doajax', {
	        url: '/communicationprotocol/list',
	         okalert:false,
	        data: {pageCurrent:pageCurrent, pageSize:pageSize},
	        okCallback: function(json, options) {
             set_list(json);
	            if(num==1){
                    $('#pagination_commu').pagination({
                        total:json.totalRow, pageSize:12, callback:pagination_callback
                    }) 
              }
              communicationprotocolTotalNum=json.totalRow;
              if(json.totalRow>pageSize){
                $("#pagination_commu").css("display","block");
              }else{
                $("#pagination_commu").css("display","none");
              }
	          }
	     })
	 }
 
function set_list(json){
   $('.commu-list-content').empty();
    var btnArr=[
        {title:"编辑",icon:"fa fa-edit",fun:"communicationprotocol_edit"},
        {title:"详情",icon:"fa fa-list-alt",fun:"communicationprotocol_detail"},
        {title:"删除",icon:"fa fa-trash-o",fun:"communicationprotocol_del"},
      ];
    $('.commu-list-content').setList(json.list,btnArr,'fa-book');

         }

function dialog_communicationprotocol_add(){
	BJUI.dialog({
		id:"communicationprotocolAdd",
		url:"/communicationprotocol/editPage",
		title:"添加通信协议字典",
    type:"post",
		width:"620",
		height:"600",
		mask:true,
    maxable:false
	})
}

function communicationprotocol_edit(obj){
        var id=$(obj).parent().parent().prevAll("#item-id").text();

        BJUI.ajax('doajax',{
          url:"/communicationprotocol/getprotocol",
          type:"post",
          okalert:false,
          dataType:"json",
          data:{"id":id},
          okCallback:function(data){  //id发送成功向页面发送信息 
            BJUI.dialog({
                 id:"appEdit",
                 url:"/communicationprotocol/editPage",
                 title:"编辑通信协议字典",
                 type:"post",
                 data:data,
                 width:"620",
                 height:"600",
                 mask:true,
                 maxable:false
                }) 
             }
          })
       }
       
function communicationprotocol_del(obj){
  var id=$(obj).parent().parent().prevAll("#item-id").text();
	BJUI.alertmsg('confirm', '确定要删除吗！', {
      okCall: function() { //点击确定时运行
  		    BJUI.ajax('doajax',{
  		           url:"/communicationprotocol/del",
  		           type:"post",
  		           dataType:"json",
  		           data: {'id':id},
                 loadingmask: true,
                 okCallback: function(json, options) {
                  communicationprotocolTotalNum -=1;
                $('#pagination_commu').pagination('destroy')
                $('#pagination_commu').pagination({
            total:communicationprotocolTotalNum, pageSize:12, callback:pagination_callback
        });
                       pagination_callback(1,12,1);
                  }
  		    })
      }
  })
		    
}

function communicationprotocol_detail(obj){  //查看私有协议字典详情
    var id=$(obj).parent().parent().prevAll("#item-id").text();
    
    BJUI.dialog({
         id:"communicationprotocolEdit",
         url:"/communicationprotocol/detail",
         title:"通信协议字典",
         type:"post",
         data:{"id":id},
         width:"620",
         height:"600",
         mask:true,
         maxable:false
        }) 
        
}
		 
</script>

